package day_1126;

import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class Company {
    private String name;
    private String scope;
    private String address;
    private List<Staff> emps = new ArrayList<>();

    /**
     * 公司有招聘员工（要求工号不能重复），有输出员工信息，
     * 以及辞退员工，和统计公司人数,获得公司薪水最高的员工的方法
     */
    public boolean hire(Staff s) {
        for (Staff staff : emps) {
            if (staff.getNo().equals(s.getNo())) {
                return false;
            }
        }
        return emps.add(s);
    }

    public boolean fire(String no) {
        for (Staff staff : emps) {
            if (staff.getNo().equals(no)) {
                emps.remove(staff);
                return true;
            }
        }
        return false;
    }

    //人数
    public int countEmps() {
        return emps.size();
    }

    //最高薪水的员工(多个只要一个)
    public Staff getTopSalary() {
        if (emps.size() == 0) {
            return null;
        }
        Staff max = emps.get(0);
        for (Staff s : emps) {
            if (max.getSalary() < s.getSalary()) {
                max = s;
            }
        }
        return max;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void show() {
        System.out.println(name + "," + scope + "," + address);
        System.out.println(emps);
    }
}
